package com.fr.web.core;

import com.fr.base.FRContext;
import com.fr.base.Inter;
import com.fr.base.core.BaseCoreUtils;
import com.fr.base.dav.LocalEnv;
import com.fr.report.RWorkBook;
import com.fr.report.ResultWorkBook;
import com.fr.report.TemplateWorkBook;
import com.fr.report.WorkBook;
import com.fr.report.io.TemplateImporter;
import com.fr.web.ReportletException;
import java.io.InputStream;
import java.util.logging.Logger;
import javax.servlet.ServletContext;

public class ServerEnv extends LocalEnv
{
  private ServletContext servletContext = null;

  public ServerEnv(ServletContext paramServletContext)
  {
    super(WebUtils.getWebINFPath(paramServletContext));
    this.servletContext = paramServletContext;
  }

  public InputStream readResource(String paramString)
  {
    return this.servletContext.getResourceAsStream(BaseCoreUtils.pathJoin(new String[] { "/", "WEB-INF", "resources", paramString }));
  }

  public boolean isTemplateExist(String paramString)
    throws Exception
  {
    if (paramString == null)
      return false;
    InputStream localInputStream = this.servletContext.getResourceAsStream(BaseCoreUtils.pathJoin(new String[] { "/", "WEB-INF", "reportlets", paramString }));
    return (localInputStream != null);
  }

  public TemplateWorkBook readTemplate(String paramString)
    throws Exception, ReportletException
  {
    if (paramString == null)
      return null;
    FRContext.getLogger().info(Inter.getLocText("INFO-Start_Reading_XML"));
    long l1 = System.currentTimeMillis();
    InputStream localInputStream = this.servletContext.getResourceAsStream(BaseCoreUtils.pathJoin(new String[] { "/", "WEB-INF", "reportlets", paramString }));
    try
    {
      WorkBook localWorkBook = new TemplateImporter().generateTemplate(localInputStream);
      return localWorkBook;
    }
    catch (ReportletException localReportletException)
    {
    }
    finally
    {
      long l2 = System.currentTimeMillis();
      FRContext.getLogger().info(Inter.getLocText("INFO-End_Reading_XML") + "\t" + Inter.getLocText("INFO-Time_Taken") + (l2 - l1) + Inter.getLocText("Milliseconds"));
    }
  }

  public ServletContext getServletContext()
  {
    return this.servletContext;
  }

  public ResultWorkBook readResult(String paramString)
    throws Exception, ReportletException
  {
    if (paramString == null)
      return null;
    FRContext.getLogger().info(Inter.getLocText("INFO-Start_Reading_XML"));
    long l1 = System.currentTimeMillis();
    InputStream localInputStream = this.servletContext.getResourceAsStream(BaseCoreUtils.pathJoin(new String[] { "/", "WEB-INF", "resultlets", paramString }));
    try
    {
      RWorkBook localRWorkBook = new TemplateImporter().generateResult(localInputStream);
      return localRWorkBook;
    }
    catch (ReportletException localReportletException)
    {
    }
    finally
    {
      long l2 = System.currentTimeMillis();
      FRContext.getLogger().info(Inter.getLocText("INFO-End_Reading_XML") + "\t" + Inter.getLocText("INFO-Time_Taken") + (l2 - l1) + Inter.getLocText("Milliseconds"));
    }
  }
}